telLogin(form1);
codeLogin(form2);

function tabs(parent) {
	this.span = parent.getElementsByTagName("span");
	this.div = parent.getElementsByTagName("div");
}
tabs.prototype.init = function() {
	this.bind();
}
tabs.prototype.bind = function() {
	var me = this;
	for(var i = 0; i < this.span.length; i++) {
		this.span[i].onclick = function() {
			me.action(this.getAttribute("order"));
		}
	}

}
tabs.prototype.action = function(num) {
	this.clear();
	this.span[num].className = "active";
	num++;
	this.div[num].className = "active";

}
tabs.prototype.clear = function() {
	for(var i = 0; i < this.span.length; i++) {
		this.span[i].className = "";
		this.div[i + 1].className = "";
	}
}

function telLogin(parent) {
	var input = parent.getElementsByTagName("input"),
		btn = parent.getElementsByTagName("button")[0];
	btn.setAttribute("disabled", true);
	var code = "",
		check = false;
	for(var i = 0; i < input.length; i++) {
		input[0].oninput = function() {
			var reg = /^(\+86|0086)?\s*[1][3-9]\d{9}$/;
			if(!reg.test(this.value)) {
				btn.disabled = true;
				btn.className = "";
			} else {
				console.log("yes");
				btn.disabled = false;
				btn.className = "active";
			}
		}
		input[1].oninput = function() {

			if(code.toLowerCase() == this.value.toLowerCase()) {
				check = true;
			} else {
				check = false;
			}
			if(this.value != "")
				input[2].style.opacity = ".9";
		}
	}
	btn.onclick = function() {
		code="";
		var arr = [];
		for(var i = 48; i <= 57; i++) {
			arr.push(String.fromCharCode(i));
		}
		for(var i = 65; i <= 90; i++) {
			arr.push(String.fromCharCode(i));
		}
		for(var i = 97; i <= 122; i++) {
			arr.push(String.fromCharCode(i));
		}
		for(var i = 0; i < 4; i++) {
			var r = parseInt(Math.random() * (arr.length));
			code += arr[r];
		}
		$("button").html(code);
		//					setInterval(function(){
		//						btn.disabled=true;
		//						btn.className="";
		//						console.log(this.value);
		//					},6000)
		//					btn.disabled=false;
		//					btn.className="active";
	}
	form1.onsubmit = function() {
		for(var i = 0; i < input.length - 1; i++) {
			if(check == false) {
				return false;
			}else{
//				alert("登录成功");
				location="index.html";
//				$(location).attr('href', 'searching.html');
//				$(window).attr('location','searching.html');
//				$(location).prop('href', 'searching.html');
			}
		}
	}
}

function codeLogin(parent) {
	var input = parent.getElementsByTagName("input");
	input[1].setAttribute("disabled", true);
	var code = "henry002",
		check = false;
	for(var i = 0; i < input.length; i++) {
		input[0].onblur = function() {
			var reg = /^(\+86|0086)?\s*[1][3-9]\d{9}$/,
				reg1 = /^[0-9a-zA-Z]+@[0-9a-zA-Z]+.com$/;
			if(!reg.test(this.value) || !reg1.test(this.value)) {
				this.style.color = "red";

			} else {
				input[1].disabled = false;
			}
		}
		input[0].oninput = function() {

			this.style.color = "#000";
		}
		input[1].onblur = function() {

			if(code == this.value) {
				check = true;
			} else {
				check = false;
				this.value = "您输入的账号或密码不正确";
				this.style.color = "red";
			}
			if(this.value != "")
				input[2].style.opacity = ".9";
		}
	}

	form2.onsubmit = function() {
		for(var i = 0; i < input.length - 1; i++) {
			if(check == false) {
				return false;
			}
		}
	}
}
var tabs1 = new tabs(tab1);
tabs1.init();